/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chat.mybean;

import java.awt.Color;
import java.awt.Graphics;
import java.util.StringTokenizer;

/**
 *
 * @author spider391Tang
 */
public class DoubleRectangleBean extends MyBean {

    int wbinnerWidth;
    int wbinnerHeight;
    Color wbinnerBackground;
    int wbouterWidth;
    int wbouterHeight;
    Color wbouterBackground;

//	innerBackground: Inner background color.
//	outerBackground: Outer background color.
//	innerWidth: Inner width.
//	innerHeight: Inner height.
//	outerWidth: Outer width.
//	outerHeight: Outer height.
    public DoubleRectangleBean() {
        wbinnerWidth = 30;
        wbinnerHeight = 30;
        wbinnerBackground = new Color(80, 80, 80);

        wbouterWidth = 80;
        wbouterHeight = 80;
        wbouterBackground = new Color(40, 50, 200);
        this.setBackground(wbouterBackground);
        this.setForeground(wbinnerBackground);
        setVisible(true);
    }

    public void paint(Graphics g) {
        super.paint(g);
        g.setColor(wbinnerBackground);
        //setBackground(wbinnerBackground);
        //g.fillOval(0, 0, wbRadius.intValue() - 1, wbRadius.intValue() - 1);
        g.fillRect(wbouterWidth/2-wbinnerWidth/2, (wbouterHeight/2)-(wbinnerHeight/2), wbinnerWidth, wbinnerHeight);
        //setSize(wbRadius.intValue(), wbRadius.intValue());
    }

    public void parseCommand(String cmd) {
        String[] buffer = new String[6];
        StringTokenizer st = new StringTokenizer(cmd);
        if (!st.hasMoreTokens()) {
            return;
        }
        for (int i = 0; i < 6; i++) {
            if (st.hasMoreTokens()) {
                buffer[i] = st.nextToken();
            } else {
                return;
            }
        }
        wbinnerBackground = Color.decode(buffer[0]);
        wbinnerHeight = Integer.parseInt(buffer[1]);
        wbinnerWidth = Integer.parseInt(buffer[2]);

        wbouterBackground = Color.decode(buffer[3]);
        wbouterHeight = Integer.parseInt(buffer[4]);
        wbouterWidth = Integer.parseInt(buffer[5]);


        setSize(wbouterWidth, wbouterHeight);
        this.setBackground(wbouterBackground);
        this.setForeground(wbinnerBackground);
        repaint();
    }

    public String toCommand() {
        String str = "";
        String[] buffer = new String[6];
        buffer[0] = getHexColor(wbinnerBackground);
        buffer[1] = String.valueOf(wbinnerHeight);
        buffer[2] = String.valueOf(wbinnerWidth);

        buffer[3] = getHexColor(wbouterBackground);
        buffer[4] = String.valueOf(wbouterHeight);
        buffer[5] = String.valueOf(wbouterWidth);

        for (int i = 0; i < 6; i++) {
            str = str + buffer[i] + " ";
        }
        return str;
    }

    public int getwbinnerWidth() {
        return wbinnerWidth;
    }

    public int getwbouterWidth() {
        return wbouterWidth;
    }

    public void setwbinnerWidth(int wbWidth) {
        this.wbinnerWidth = wbWidth;
    }

    public void setwbouterWidth(int wbWidth) {
        this.wbouterWidth = wbWidth;
    }

    public int getwbinnerHeight() {
        return wbinnerHeight;
    }

    public int getwbouterHeight() {
        return wbouterHeight;
    }

    public void setwbinnerHeight(int wbHeight) {
        this.wbinnerHeight = wbHeight;
    }

    public void setwbouterHeight(int wbHeight) {
        this.wbouterHeight = wbHeight;
    }

    public Color getwbinnerBackground() {
        return wbinnerBackground;
    }

    public Color getwbouterBackground() {
        return wbouterBackground;
    }

    public void setwbinnerBackground(Color wbBackColor) {
        this.wbinnerBackground = wbBackColor;
    }

    public void setwbouterBackground(Color wbBackColor) {
        this.wbouterBackground = wbBackColor;
    }

    private String getHexColor(Color cColor) {
        int iTmp = 0;
        iTmp = cColor.getRed();
        iTmp *= 256;
        iTmp += cColor.getGreen();
        iTmp *= 256;
        iTmp += cColor.getBlue();
        String tmp = Integer.toHexString(iTmp);
        while (tmp.length() < 6) {
            tmp = "0" + tmp;
        }
        tmp = "#" + tmp;
        return tmp;
    }
}
